
const BaseUrl = '/'


function post(url, params, _config) {
    let config = Object.assign({
        token: true, //默认不需要token参数
        check: true, //默认要判断返回的状态,
        responseType: 'json'
    }, _config);

    if (config.token) {
        // params.token = getToken()
    }

    return new Promise((resolve, reject) => {
        axios.post(BaseUrl + url, params, {
            responseType: config.responseType, headers: {
                'Content-Type': 'application/json'
            }, transformRequest: [function (data) {
                data = JSON.stringify(data)
                return data
            }],
        })
            .then(res => {
                if (config.check) {
                    if (res.data.success !== 'true') {
                        vueApp.$message.error(res.data.message || '未知错误')
                        reject(res);
                    } else {
                        resolve(res.data);
                    }
                } else {
                    resolve(res.data);
                }
            })
            .catch(err => {
                // reject(err.data)
                vueApp.$message.error('请求服务器失败')
                reject(err);
            })
    });
}

function get(url, params) {
    return new Promise((resolve, reject) => {
        // params.token = getToken()
        let q = '?'
        for (let k in params) {
            q += `${k}=${params[k]}&`
        }
        axios.get(BaseUrl + url + q, params)
            .then(res => {
                if (res.data.success !== 'true') {
                    vueApp.$message.error(res.data.message || '未知错误')
                    reject(res);
                } else {
                    resolve(res.data);
                }
            })
            .catch(err => {
                vueApp.$message.error('请求服务器失败')
                reject(err.data)
            })
    });
}


// 接口列表
// const api_userSign = (params) => post('api/user/sign', params, {}); // 每日签到
const adminApi_getGoodsList = () => get('admin/shop/goods', {}, {});
const adminApi_saveGoods = (p) => post('admin/shop/save/'+p.id, p, {});
const adminApi_delGoods = (p) => post('admin/shop/destroy', p, {});
const adminApi_orderList = (p) => get('admin/shop/orderList', p, {});
const adminApi_posterOrder = (p) => post('admin/shop/posterOrder', p, {});
const adminApi_getAddress = (p) => get('admin/shop/getAddress/'+p.id, p, {});

const adminApi_getGameTagList = () => get('admin/gameTag/list', {}, {});
const adminApi_saveGameTag = (p) => post('admin/gameTag/save/'+p.id, p, {});
const adminApi_delGameTag = (p) => post('admin/gameTag/destroy', p, {});
const adminApi_getAbnormalExtract = (p) => get('admin/games/getAbnormalExtract', p, {});

const adminApi_getConfig = () => get('admin/config/get', {}, {});
const adminApi_setConfig = (p) => post('admin/config/save', p, {});

const adminApi_getAdmin = () => get('admin/admin/list', {}, {});
const adminApi_saveAdmin = (p) => post('admin/admin/save/'+p.id, p, {});
const adminApi_delAdmin = (p) => post('admin/admin/destroy', p, {});

const adminApi_yjjyList = (p) => get('admin/yjjy/list', p, {});


const adminApi_getBalanceLog = (p) => get('admin/users/getBalanceLog', p, {});
const adminApi_getBalanceLogStatistic = (p) => get('admin/users/getBalanceLogStatistic', p, {});
const adminApi_getGameRechargeLog = (p) => get('admin/recharge/getGameRechargeList', p, {});

const adminApi_getLoginRechargeStatistic = (p) => get('admin/dashboard/getLoginRechargeStatistic', p, {});
const adminApi_getLoginRechargeTotalStatistic = (p) => get('admin/dashboard/getLoginRechargeTotalStatistic', p, {});
const adminApi_getNewUserRechargeInfo = (p) => get('admin/dashboard/getNewUserRechargeInfo', p, {});

const adminApi_getCustomServiceLevelList = (p) => get('admin/customService/getLevelList', p, {});
const adminApi_saveCustomServiceLevel = (p) => post('admin/customService/saveLevel', p, {});
const adminApi_saveCustomService = (p) => post('admin/customService/saveService', p, {});
const adminApi_bindCustomServiceUser = (p) => post('admin/customService/bindService', p, {});
const adminApi_getCustomServiceList = (p) => get('admin/customService/getServiceList', p, {});
const adminApi_getCustomServiceBindCode = (p) => get('admin/customService/getServiceBindCode', p, {});
const adminApi_getUserUpgradeLog = (p) => get('admin/customService/getUserUpgradeLog', p, {});
const adminApi_setCustomServicePwd = (p) => post('admin/customService/setPassword', p, {});

const adminApi_getUserLevelList = (p) => get('admin/userLevel/getList', p, {});

const adminApi_activateGetLbList = (p) => get('admin/activate/getLbList', p, {});
const adminApi_activateGetLbGetLog = (p) => get('admin/activate/getLbGetLog', p, {});
const adminApi_activateGetFiveDayList = (p) => get('admin/activate/getFiveDayList', p, {});


const adminApi_getBirthdayGiftList = (p) => get('admin/users/getBirthdayGiftList', p, {});
const adminApi_getGiftList = (p) => get('admin/users/getGiftList', p, {});
const adminApi_getWaitFestivalList = (p) => get('admin/users/getWaitFestivalList', p, {});
const adminApi_getFestival = (p) => get('admin/users/getFestival', p, {});
const adminApi_sendBirthdayOrJrGift = (p) => post('admin/users/sendGift', p, {});
